// com.city.java.announcements.controller.AnnouncementController.java
package com.city.java.announcements.controller;

import com.city.java.announcements.pojo.dto.AnnouncementQuery;
import com.city.java.announcements.pojo.entity.Announcements;
import com.city.java.announcements.service.AnnouncementService;
import com.city.java.base.response.JsonResult;
import com.city.java.base.utils.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 公告控制器
 * RestController注解: 组合注解，相当于@Controller + @ResponseBody
 * Api注解: Knife4j文档中模块的显示名称
 * RequestMapping注解: 设置统一的请求路径前缀
 */
@Slf4j
@Api(tags = "09.公告管理模块")
@RestController
@RequestMapping("/api/announcements")
public class AnnouncementController {

    @Autowired
    private AnnouncementService announcementService;

    /**
     * 添加公告
     * PostMapping注解: 处理POST请求
     * ApiOperation注解: Knife4j文档中接口的显示名称
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加公告", notes = "添加新公告信息")
    public JsonResult addAnnouncement(
            @ApiParam(value = "公告信息", required = true)
            @RequestBody Announcements announcement) {
        log.info("接收到添加公告请求: {}", announcement);
        return announcementService.addAnnouncement(announcement);
    }

    /**
     * 根据公告ID查询公告
     * GetMapping注解: 处理GET请求
     * PathVariable注解: 获取路径中的参数
     */
    @GetMapping("/select/id/{announcementId}")
    @ApiOperation(value = "根据ID查询公告", notes = "根据公告ID查询公告详细信息")
    public JsonResult getAnnouncementById(
            @ApiParam(value = "公告ID", required = true, example = "1")
            @PathVariable Long announcementId) {
        log.info("接收到根据ID查询公告请求: ID={}", announcementId);
        return announcementService.getAnnouncementById(announcementId);
    }

    /**
     * 根据类型和状态查询公告列表
     */
    @GetMapping("/select/filter/filter")
    @ApiOperation(value = "根据类型和状态查询公告", notes = "根据类型和状态查询公告列表")
    public JsonResult getAnnouncementsByTypeAndStatus(
            @ApiParam(value = "公告类型", example = "COMMUNITY")
            @RequestParam(required = false) Announcements.AnnouncementType type,
            @ApiParam(value = "公告状态", example = "FINALIZED")
            @RequestParam(required = false) Announcements.AnnouncementStatus status) {
        log.info("接收到根据类型和状态查询公告请求: type={}, status={}", type, status);
        return announcementService.getAnnouncementsByTypeAndStatus(type, status);
    }

    /**
     * 根据标题查询公告列表
     */
    @GetMapping("/select/title")
    @ApiOperation(value = "根据标题查询公告", notes = "根据标题查询公告列表")
    public JsonResult getAnnouncementsByTitle(
            @ApiParam(value = "公告标题", required = true, example = "停水通知")
            @RequestParam String title) {
        log.info("接收到根据标题查询公告请求: title={}", title);
        return announcementService.getAnnouncementsByTitle(title);
    }

    /**
     * 查询所有公告列表
     */
    @GetMapping("quarry")
    @ApiOperation(value = "查询所有公告", notes = "查询所有公告列表")
    public JsonResult getAllAnnouncements() {
        log.info("接收到查询所有公告请求");
        return announcementService.getAllAnnouncements();
    }

    /**
     * 分页查询公告列表
     */
    @GetMapping("/select")
    @ApiOperation(value = "分页查询公告", notes = "分页查询公告列表")
    public JsonResult select(AnnouncementQuery query) {
        log.info("接收到分页查询公告请求: {}", query);
        PageVO<Announcements> pageVO = announcementService.select(query);
        return JsonResult.ok(pageVO);
    }

    /**
     * 根据公告ID删除公告
     * DeleteMapping注解: 处理DELETE请求
     */
    @DeleteMapping("/delete/id/{announcementId}")
    @ApiOperation(value = "根据ID删除公告", notes = "根据公告ID删除公告")
    public JsonResult deleteAnnouncementById(
            @ApiParam(value = "公告ID", required = true, example = "1")
            @PathVariable Long announcementId) {
        log.info("接收到根据ID删除公告请求: ID={}", announcementId);
        return announcementService.deleteAnnouncementById(announcementId);
    }

    /**
     * 更新公告信息
     * PutMapping注解: 处理PUT请求
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新公告信息", notes = "更新公告详细信息")
    public JsonResult updateAnnouncement(
            @ApiParam(value = "公告信息", required = true)
            @RequestBody Announcements announcement) {
        log.info("接收到更新公告信息请求: {}", announcement);
        return announcementService.updateAnnouncement(announcement);
    }
}
